<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-dis.html" />
<link rel="prev" href="module-pycompile.html" />
<link rel="parent" href="language.html" />
<link rel="next" href="module-dis.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>30.9 compileall -- Byte-compile Python libraries</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="30.8 py_compile  "
  href="module-pycompile.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="30. python Language Services"
  href="language.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="30.10 dis  "
  href="module-dis.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-pycompile.html">30.8 py_compile  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="language.html">30. Python Language Services</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-dis.html">30.10 dis  </a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION0032900000000000000000">
30.9 <tt class="module">compileall</tt> --
         Byte-compile Python libraries</a>
</h1>

<p>
<a name="module-compileall"></a>

<p>
This module provides some utility functions to support installing
Python libraries.  These functions compile Python source files in a
directory tree, allowing users without permission to write to the
libraries to take advantage of cached byte-code files.

<p>
The source file for this module may also be used as a script to
compile Python sources in directories named on the command line or in
<code>sys.path</code>.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5469' xml:id='l2h-5469' class="function">compile_dir</tt></b>(</nobr></td>
  <td><var>dir</var><big>[</big><var>, maxlevels</var><big>[</big><var>,
                              ddir</var><big>[</big><var>, force</var><big>[</big><var>, 
                              rx</var><big>[</big><var>, quiet</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Recursively descend the directory tree named by <var>dir</var>, compiling
  all <span class="file">.py</span> files along the way.  The <var>maxlevels</var> parameter
  is used to limit the depth of the recursion; it defaults to
  <code>10</code>.  If <var>ddir</var> is given, it is used as the base path from 
  which the filenames used in error messages will be generated.  If
  <var>force</var> is true, modules are re-compiled even if the timestamps
  are up to date. 

<p>
If <var>rx</var> is given, it specifies a regular expression of file
  names to exclude from the search; that expression is searched for in
  the full path.

<p>
If <var>quiet</var> is true, nothing is printed to the standard output
  in normal operation.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5470' xml:id='l2h-5470' class="function">compile_path</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>skip_curdir</var><big>[</big><var>,
                               maxlevels</var><big>[</big><var>, force</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Byte-compile all the <span class="file">.py</span> files found along <code>sys.path</code>.
  If <var>skip_curdir</var> is true (the default), the current directory is
  not included in the search.  The <var>maxlevels</var> and
  <var>force</var> parameters default to <code>0</code> and are passed to the
  <tt class="function">compile_dir()</tt> function.
</dl>

<p>
To force a recompile of all the <span class="file">.py</span> files in the <span class="file">Lib/</span>
subdirectory and all its subdirectories:

<p>
<div class="verbatim"><pre>
import compileall

compileall.compile_dir('Lib/', force=True)

# Perform same compilation, excluding files in .svn directories.
import re
compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True)
</pre></div>

<p>
<div class="seealso">
  <p class="heading">See Also:</p>

  <dl compact="compact" class="seemodule">
    <dt>Module <b><tt class="module"><a href="module-pycompile.html">py_compile</a></tt>:</b>
    <dd>Byte-compile a single source file.
  </dl>
</div>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="30.8 py_compile  "
  href="module-pycompile.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="30. python Language Services"
  href="language.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="30.10 dis  "
  href="module-dis.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-pycompile.html">30.8 py_compile  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="language.html">30. Python Language Services</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-dis.html">30.10 dis  </a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
